<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<!-- HTML file produced from file: manual.tex --
 -- using Hyperlatex v 2.3.1 (c) Otfried Cheong--
 -- on Emacs 21.4 (patch 15) "Security Through Obscurity" XEmacs Lucid, Fri Dec  3 20:36:24 2004 -->
<HEAD>
<TITLE>Scheme 48 Manual -- Creating and controlling threads</TITLE>

</HEAD><BODY BGCOLOR="#ffffff">
<EM>Scheme 48 Manual</EM> | <A HREF="s48manual.html#top_node">Contents</A> | In Chapter: <A HREF="s48manual_57.html">Threads</A><BR>Previous: <A HREF="s48manual_58.html">Creating and controlling threads</A> | Next: <A HREF="s48manual_58.html">Creating and controlling threads</A>
<H2>Creating and controlling threads</H2>
<P>The bindings described in this section are part of the <CODE>threads</CODE>
structure.
<UL><LI><CODE>(spawn<I>&nbsp;thunk</I>)&nbsp;-&gt;&nbsp;<I>thread</I></CODE><A NAME="1">&nbsp;</A>
<LI><CODE>(spawn<I>&nbsp;thunk&nbsp;name</I>)&nbsp;-&gt;&nbsp;<I>thread</I></CODE><A NAME="2">&nbsp;</A>
</UL>
<CODE>Spawn</CODE> creates a new thread, passes that thread to the current
scheduler, and instructs the scheduler to run <CODE><I>thunk</I></CODE> in that
thread.  The <CODE><I>name</I></CODE> argument (a symbol) associates a symbolic
name with the thread; it is purely for debugging purposes.
<UL><LI><CODE>(relinquish-timeslice<I></I>)</CODE><A NAME="3">&nbsp;</A>
<LI><CODE>(sleep<I>&nbsp;time-in-milliseconds</I>)</CODE><A NAME="4">&nbsp;</A>
<LI><CODE>(terminate-current-thread<I></I>)</CODE><A NAME="5">&nbsp;</A>
</UL>
<CODE>Relinquish-timeslice</CODE> instructs the scheduler to run another
thread, thus relinquishing the timeslice of the current thread.
<CODE>Sleep</CODE> does the same and asks the scheduler to suspend the
current thread for at least <CODE><I>time-in-milliseconds</I></CODE> milliseconds
before resuming it.  Finally, <CODE>terminate-current-thread</CODE>
terminates the current thread.
<P>Each thread is represented by a thread object.  The following
procedures operate on that object:
<UL><LI><CODE>(current-thread<I></I>)&nbsp;-&gt;&nbsp;<I>thread</I></CODE><A NAME="6">&nbsp;</A>
<LI><CODE>(thread?<I>&nbsp;thing</I>)&nbsp;-&gt;&nbsp;<I>boolean</I></CODE><A NAME="7">&nbsp;</A>
<LI><CODE>(thread-name<I>&nbsp;thread</I>)&nbsp;-&gt;&nbsp;<I>name</I></CODE><A NAME="8">&nbsp;</A>
<LI><CODE>(thread-uid<I>&nbsp;thread</I>)&nbsp;-&gt;&nbsp;<I>integer</I></CODE><A NAME="9">&nbsp;</A>
</UL>
<CODE>Current-thread</CODE> returns the thread object associated with the
currently running thread.  
<CODE>Thread?</CODE> is the predicate for thread objects.
<CODE>Thread-name</CODE> extracts the name of the thread, if one was
specified in the call to <CODE>spawn</CODE>, <CODE>#f</CODE> otherwise.
<CODE>Thread-uid</CODE> returns the <I>uid</I> of the thread, a unique
integer assigned by the thread system.
<P><P>
  
Previous: <A HREF="s48manual_58.html">Creating and controlling threads</A> | Next: <A HREF="s48manual_58.html">Creating and controlling threads</A></BODY></HTML>
